<!--suppress ALL -->
<include file="./Template/header.html" />

<if condition="$payPageType eq C('PAY_PAGE_TYPE.ORDER')">

	<link rel="stylesheet" type="text/css" href="/Template/css/confirmOrder.css">
	<script type="text/javascript">

        $(function() {

            //初始化页面配置
            document.title = "订单支付";

            var app = new Vue({
                el: '#container',
                data: {
                    orderList: [],
                },
                methods: {
                    index: indexPage,
                    order: orderPage,
                    rank: rankPage,
                    center: centerPage,
                }
            })

            wx.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: '{$webarr.appId}', // 必填，公众号的唯一标识
                timestamp: '{$config.timestamp}', // 必填，生成签名的时间戳
                nonceStr: '{$config.noncestr}', // 必填，生成签名的随机串
                signature: '{$config.signature}', // 必填，签名，见附录1
                jsApiList: ['chooseWXPay'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
            });

            wx.ready(function(){});

            function callpay(){
                if (typeof WeixinJSBridge == "undefined"){
                    if( document.addEventListener ){
                        alert("必须在微信中支付");
                        document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                    }else if (document.attachEvent){
                        alert("必须在微信中支付2");
                        document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                        document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                    }
                }else{
                    onBridgeReady();
                }
            }

            function onBridgeReady(){
                wx.chooseWXPay({
                    timestamp: '{$webarr.timeStamp}', // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                    nonceStr: '{$webarr.nonceStr}', // 支付签名随机串，不长于 32 位
                    package: '{$webarr.package}', // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
                    signType: '{$webarr.signType}', // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
                    paySign: '{$webarr.paySign}', // 支付签名
                    success: function (res) {
                        // 支付成功后的回调函数
                        window.location.href = "{$successUrl}";
                    }
                });
            }

            $(".pay").on('click',function(){
                if (parseInt($('.price span').text()) > parseInt($('.remain-money span').text())) {
                    $('.other-pay').removeClass('active');
                }else{
                    $(this).addClass('active').siblings('.pay').removeClass('active');
                }
            });

            $(".btn-weui").on("click",function() {
                if($(".other-pay").hasClass('active')) {
                    $.ajax({
                        url:"/wechat/product/balancePay",
                        type:"post",
                        data:{
                            orderId:'{$order.order_id}',
                        },
                        dataType:"JSON",
                        beforeSend:function(){
                            $("#loadingToast").show();
                        },
                        complete:function(){
                            $('#loadingToast').hide();
                        },
                        success:function(data){
                            if(data.code != 200) {
                                alert(data.msg);
                            } else {
                                window.location.href = "{:U('Product/paySuccess',array('id'=>$order['order_id']))}";
                            }
                        },
                    })
                } else {
                    callpay();
                }

            })

        });


	</script>
	<div class="confirm-order">
		<div class="goods-info">
			<div class="goods-img" style="background:url('{$group.image}')no-repeat center;background-size: cover;"></div>
			<div class="goods">
				<p class="goods-title color-font">{$group.product_name}</p>
			</div>
			<div class="tag bg-yellow">
				<i></i>
				<span>第{$group.current_round}轮</span>
			</div>
		</div>
		<div class="user-info">
			<div class="user-img" style="background:url('{$group.headimgurl}')no-repeat center;background-size: cover;"></div>
			<div class="user-title color-font">
				<p>{$group.nickname}</p>
				<p class="have-num">持<span class="color-99">{$member.number}</span>份</p>
			</div>
		</div>
		<div class="pay-list">
			<div class="pay-list-info">
				<p class="num">份数：{$order.number}</p>
				<p class="price">总价 <span>{$order.number}</span></p>
			</div>
		</div>
		<div class="pay-type">
			<p>支付方式</p>
		</div>
		<div class="pay wx-pay active">
			<i class="icon-check"></i>
			<p>微信支付</p>
		</div>
		<div class="pay other-pay">
			<i class="icon-check"></i>
			<p>团金币支付</p>
			<p class="remain-money">可用团金币<span>{$balance}</span></p>
		</div>
	</div>
	<div class="btn-weui">
		<p>确认支付</p>
	</div>

<elseif condition="$payPageType eq C('PAY_PAGE_TYPE.RECEIVE')"/>
	<link rel="stylesheet" type="text/css" href="/Template/css/common.css">
	<link rel="stylesheet" type="text/css" href="/Template/css/confirmOrderPrice.css">

	<script type="text/javascript">

        $(function() {
            //初始化页面配置
            document.title = "确认订单";

            wx.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: '{$webarr.appId}', // 必填，公众号的唯一标识
                timestamp: '{$config.timestamp}', // 必填，生成签名的时间戳
                nonceStr: '{$config.noncestr}', // 必填，生成签名的随机串
                signature: '{$config.signature}', // 必填，签名，见附录1
                jsApiList: ['chooseWXPay'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
            });

            wx.ready(function(){});

            function callpay(){
                if (typeof WeixinJSBridge == "undefined"){
                    if( document.addEventListener ){
                        alert("必须在微信中支付");
                        document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                    }else if (document.attachEvent){
                        alert("必须在微信中支付2");
                        document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                        document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                    }
                }else{
                    onBridgeReady();
                }
            }

            function onBridgeReady(){
                wx.chooseWXPay({
                    timestamp: '{$webarr.timeStamp}', // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                    nonceStr: '{$webarr.nonceStr}', // 支付签名随机串，不长于 32 位
                    package: '{$webarr.package}', // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
                    signType: '{$webarr.signType}', // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
                    paySign: '{$webarr.paySign}', // 支付签名
                    success: function (res) {
                        // 支付成功后的回调函数
                        alert('恭喜您兑换成功！请耐心等待快递上门哦，虚拟物品的领取请尽快点击公众号里的“平台服务”联系我们的客服吧')
                        window.location.href = "{$successUrl}";
                    }
                });
            }

            $(".bg-pay").on("click",function() {
				callpay();
            })

        });

	</script>
	<div class="confirm-order">
		<div class="goods-info">
			<div class="goods-img" style="background: url('{$order.image}')no-repeat center;background-size: cover;"></div>
			<div class="goods">
				<p class="goods-title color-font">{$order.product_name}</p>
			</div>
			<div class="tag bg-yellow">
				<span>中奖产品</span>
			</div>
		</div>
		<div class="need-pay-price">
			<p class="color-font">需支付 {$giftOrder.price}</p>
		</div>
        <p class="why-need-pay">为什么要补差价？</p>
        <p class="why-need-pay">去开团规则为一人中奖则全团中奖，中奖后您所在团的全体成员将瓜分奖品。</p>
        <p class="why-need-pay">因奖品只有一份，所以您需要支付其他团员应得奖励等额的团金币即可领取奖品。</p>
        <p class="why-need-pay">您也可以选择将奖品返还给去开团平台（以95折结算）换成团金币，直接按照成团时您支付的团金币比例获得您的份额，剩余份额将按比例自动发放至其他团员的账户中。</p>
        <p class="why-need-pay">点击返回即可重新选择分配方式</p>
        <p class="why-need-pay">点击下面按钮支付团友份额，请填写您的收货地址，我们会为您闪电发货！</p>
        
	</div>
	<div class="btn-weui bg-pay">
		<p>微信支付</p>
	</div>

</if>

<!-- loading toast -->
<div id="loadingToast" class="weui_loading_toast" style="display: none;">
	<div class="weui_mask_transparent"></div>
	<div class="weui_toast small">
		<div class="weui_loading">
			<div class="weui_loading_leaf weui_loading_leaf_0"></div>
			<div class="weui_loading_leaf weui_loading_leaf_1"></div>
			<div class="weui_loading_leaf weui_loading_leaf_2"></div>
			<div class="weui_loading_leaf weui_loading_leaf_3"></div>
			<div class="weui_loading_leaf weui_loading_leaf_4"></div>
			<div class="weui_loading_leaf weui_loading_leaf_5"></div>
			<div class="weui_loading_leaf weui_loading_leaf_6"></div>
			<div class="weui_loading_leaf weui_loading_leaf_7"></div>
			<div class="weui_loading_leaf weui_loading_leaf_8"></div>
			<div class="weui_loading_leaf weui_loading_leaf_9"></div>
			<div class="weui_loading_leaf weui_loading_leaf_10"></div>
			<div class="weui_loading_leaf weui_loading_leaf_11"></div>
		</div>
		<p class="weui_toast_content">正在处理</p>
	</div>
</div>
<!--end loading toast-->